package com.chenfubing.ps.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chenfubing.ps.entity.Community;
import com.chenfubing.ps.entity.pojo.CommunityNumber;
import com.chenfubing.ps.entity.pojo.CountPojo;
import com.chenfubing.ps.mapper.CommunityMapper;
import com.chenfubing.ps.service.ICommunityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenfubing.ps.service.IndexService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenfubing
 * @since 2020-05-05
 */
@Service
public class CommunityServiceImpl extends ServiceImpl<CommunityMapper, Community> implements ICommunityService {

    @Resource
    private IndexService indexService;

    @Override
  public   List<Community> getCommunityList(){
        return baseMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public void addCommunity(Community community) {
        baseMapper.insert(community);
    }

    @Override
    public CommunityNumber getCommunityNumber(int id) {
        CountPojo countPojo = indexService.getCountPojo();
        Community community = baseMapper.selectById(id);
        return new CommunityNumber().setCommunitySpaceNumber(community.getCommunitySpaceNumber()).setCommunitySpaceLastNumber(countPojo.getSpaceCount());
    }

}
